package com.ztk.threadbasic.excel.handler;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.util.BooleanUtils;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.AbstractCellStyleStrategy;
import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy;
import org.apache.poi.ss.usermodel.*;


public class CustomCellStyleStrategy extends AbstractCellStyleStrategy {

    @Override
    public void setContentCellStyle(CellWriteHandlerContext context) {
        Cell cell = context.getCell();
        Workbook workbook = cell.getSheet().getWorkbook();
        DataFormat dataFormat = workbook.createDataFormat();
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setDataFormat(dataFormat.getFormat("#,##0.00%")); // 设置两位小数的百分比格式
        cell.setCellStyle(cellStyle);
        context.getFirstCellData().setWriteCellStyle(null);
    }

}
